package com.rabbitmq.receiver;

import com.rabbitmq.entity.MessageEntity;
import com.rabbitmq.websocket.WebSocketServer;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = "messageQueue")//监听的队列名称
public class DirectReceiver {
    @RabbitHandler
    public void process(MessageEntity messageEntity) {
        System.out.println("DirectReceiver消费者收到消息  : " + messageEntity.toString());
        try {
            WebSocketServer.sendMessage(messageEntity,String.valueOf(messageEntity.getUserId()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}